package com.server.questionbank.snframe.util.FileUtil.operation.base;

import io.minio.MinioClient;
import org.apache.commons.lang3.StringUtils;

public abstract class AbstractOperation<T> implements Operation<T> {
    protected final MinioClient minioClient;
    protected final String bucket;
    protected final String object;

    protected AbstractOperation(MinioClient minioClient, String bucket, String object) {
        this.minioClient = minioClient;
        this.bucket = bucket;
        this.object = object;
    }

    @Override
    public T execute() throws Exception {
        validate();
        return doExecute();
    }

    protected abstract T doExecute() throws Exception;

    @Override
    public void validate() {
        if (StringUtils.isEmpty(bucket)) {
            throw new IllegalArgumentException("Bucket name cannot be empty");
        }
        if (StringUtils.isEmpty(object)) {
            throw new IllegalArgumentException("Object name cannot be empty");
        }
    }
} 